// pages/search/search.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    searchParams:{},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var searchParams = this.data.searchParams
    if (options.type == 1 || options.type == 2 || options.type ==3){
      searchParams.type = options.type
      this.setData({
        searchParams: searchParams
      })
    }
    this.getProjectList(searchParams)
  },

  search:function(res){
    var searchParams = this.data.searchParams
    console.log(res.detail.value)
    searchParams.name = res.detail.value
    this.getProjectList(searchParams)
  },

  getProjectList: function (searchParams) {
    wx.showLoading({
      title: '加载中',
    })
    var that = this
    wx.request({
      url: app.host + '/project/search',
      header: {
        accessToken: app.accessToken
      },
      data: searchParams,
      method: "post",
      complete: function (res) {
        wx.hideLoading()
        console.log(res)
        if (res.statusCode == 200) {
          if (res.data.code == 0) {
            that.setData({
              projectList: res.data.data
            })
          }else{
            console.log(res.data.msg)
          }
        }else{
          console.log("无法连接服务")
        }
      }
    })
  },

  toProjectDetail: function (e) {
    console.log(e)
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/portal/project/detail/detail?id=' + id,
    })
  },


})